home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1993 November / JCSM Shareware Collection - 1993-11.iso / cl720 / panel23j.lzh / HELP.C < prev    next >
Text File  |  1991-10-09  |  5KB  |  200 lines

  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <malloc.h>
  4.  
  5. #include "panel.h"
  6. #include "keys.h"
  7.  
  8. FILE *handle;
  9. char fn[20];
  10. char *text[500];
  11. char *newln;
  12. char buf[80];
  13. int lines, cur_line;
  14.  
  15. void process_topic(int);
  16. void move(int);
  17.  
  18.  
  19. /*************  main  ***************/
  20.  
  21. main()
  22.     {
  23.     int topic = 1;
  24.     unsigned aid = 0;
  25.  
  26.     pan_init();
  27.  
  28.     pan_activate("helpmenu");
  29.  
  30.     for (;;)
  31.         {
  32.         pan_put_field("stat", 1,
  33.         "  [Home]=First topic  []=Prior  []=Next  [End]=Last topic  [Enter]=Select");
  34.  
  35.         pan_field_attr("topic", topic, "pr6");
  36.         aid = pan_get_key();
  37.         pan_field_attr("topic", topic, "ph6");
  38.         switch (aid)
  39.             {
  40.             case UP:
  41.                 if (topic > 1)
  42.                     topic--;
  43.                 break;
  44.             case DOWN:
  45.                 if (topic < 6)
  46.                     topic++;
  47.                 break;
  48.             case HOME:
  49.                 topic = 1;
  50.                 break;
  51.             case END:
  52.                 topic = 6;
  53.                 break;
  54.             case ENTER:
  55.                 if (topic < 6)
  56.                     process_topic(topic);
  57.                 else
  58.                     {
  59.                     pan_destroy();
  60.                     exit(0);
  61.                     }
  62.                 break;
  63.             }
  64.  
  65.         }
  66.  
  67.  
  68.     }
  69.  
  70.  
  71. /*************  process_topic  ***************/
  72.  
  73. void process_topic(topic)
  74. int topic;
  75.     {
  76.     int i;
  77.     unsigned aid;
  78.  
  79.     sprintf(fn, "help%d.txt", topic);
  80.     if ((handle = fopen(fn, "r")) == NULL)
  81.         {
  82.         sprintf(buf, "%s - file not found!", fn);
  83.         pan_error(16, __LINE__, buf);
  84.         }
  85.  
  86.     pan_put_field("stat", 1,
  87.     "        [Esc]=Menu      [PgDn]=Next page      [PgUp]=Prior page  ");
  88.  
  89.     lines = 0;
  90.     fgets(buf, 80, handle);
  91.     while ((!feof(handle)) && (lines < 500))
  92.         {
  93.         newln = strrchr(buf, '\n');
  94.         if (newln != NULL)
  95.             *newln = 0;
  96.  
  97.         text[lines] = (char *)malloc(80);
  98.         if (text[lines] == NULL)
  99.             {
  100.             pan_error(16, __LINE__, "Out of memory!");
  101.             }
  102.  
  103.         strcpy(text[lines], buf);
  104.  
  105.         lines++;
  106.         fgets(buf, 80, handle);
  107.         }
  108.  
  109.     fclose(handle);
  110.  
  111.     pan_activate("helpskel");
  112.  
  113.     move(cur_line = 0);
  114.  
  115.     while ((aid = pan_get_key()) != ESC)
  116.         switch (aid)
  117.             {
  118.             case PGDN:
  119.                 if (cur_line < lines - 19)
  120.                     cur_line += 20;
  121.                 move(cur_line);
  122.                 break;
  123.             case PGUP:
  124.                 if (cur_line >= 20)
  125.                     cur_line -= 20;
  126.                 else
  127.                     if (cur_line > 0)
  128.                         cur_line = 0;
  129.                 move(cur_line);
  130.                 break;
  131.             case F1:
  132.                 if (topic == 3)
  133.                     {
  134.                     pan_activate("helpex1");
  135.                     pan_execute("", 1, 0);
  136.                     pan_destroy();
  137.                     }
  138.                 break;
  139.             case F2:
  140.                 if (topic == 3)
  141.                    {
  142.                     pan_activate("helpex2");
  143.                     pan_execute("", 1, 0);
  144.                     pan_destroy();
  145.                     }
  146.                 break;
  147.             case F3:
  148.                 if (topic == 3)
  149.                    {
  150.                     pan_activate("helpex3");
  151.                     pan_get_key();
  152.                     pan_destroy();
  153.                    }
  154.                 break;
  155.             }
  156.  
  157.  
  158.     pan_destroy();
  159.  
  160.     for (i=0; i<lines; i++)
  161.         free(text[i]);
  162.  
  163.     }
  164.  
  165.  
  166. /*************  move  ***************/
  167.  
  168. void move(sub)
  169. int sub;
  170.     {
  171.     int i, j;
  172.  
  173.     for (i=1; i<=20; i++)
  174.         if ((i+sub) > lines)
  175.             {
  176.             pan_put_field("line", i, "");
  177.             pan_field_attr("line", i, "p7");
  178.             }
  179.         else
  180.             {
  181.             j = i + sub - 1;
  182.             if (strlen(text[j]) > 1)
  183.                 {
  184.                 if (*text[j] == '+')
  185.                     pan_field_attr("line", i, "ph6");
  186.                 else
  187.                     pan_field_attr("line", i, "p7");
  188.                 pan_put_field("line", i, text[j]+1);
  189.                 }
  190.             else
  191.                 {
  192.                 pan_put_field("line", i, "");
  193.                 pan_field_attr("line", i, "p7");
  194.                 }
  195.             }
  196.  
  197.     }
  198.  
  199.  
  200.